package com.ft.sso.secrityauthor2sso.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * @Author RenPu
 * @Date 2022/9/28 11:32
 * @Version 1.0
 * @Description: 获取用户的账号和密码交给security进行认证校验
 **/

@Service
public class UserService implements UserDetailsService {

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
       //todo 此处需要更数据交互进行获取用户的账户和密码信息
        //案例中直接封装为固定用户值
        String password = passwordEncoder.encode("123456");
        return new User("renpu",password, AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));

    }
}
